﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TSL.Web.UI
{
    public class BaseManage : System.Web.UI.Page
    {
        private TSL.Model.webconfig _webconfig = null;
        public TSL.Model.webconfig WebConfig
        {
            get
            {
                if (_webconfig == null)
                {
                    _webconfig = new TSL.BLL.webconfig().GetModelByCache();
                }
                return _webconfig;
            }
            set
            {
                _webconfig = value;
            }
        }

        public string WebSiteName()
        {
            if (WebConfig != null && WebConfig.URL != String.Empty)
            {
                return WebConfig.name;
            }
            else
            {
                return "UK";
            }
        }

        /// <summary>
        /// 检测当前用户是否登录 只适用于普通会员
        /// </summary>
        public bool IsLogin
        {
            get
            {
                bool login = false;
                if ((this.Session["HTUserName"] != null) && (!string.IsNullOrEmpty(this.Session["HTUserName"].ToString())))
                    login = true;
                return login;
            }
        }

        /// <summary>
        /// 返回用户名 只适用于普通会员 如果没有登录 返回空
        /// </summary>
        public string UserName
        {
            get
            {
                string username = String.Empty;
                if (AsUser != null)
                {
                    username = AsUser.username;
                }
                return username;
            }
        }

        private TSL.Model.SYS_users _asuser = null;
        /// <summary>
        /// 返回当前登录的用户model
        /// </summary>
        public TSL.Model.SYS_users AsUser
        {
            get
            {
                if (_asuser == null)
                {
                    if ((this.Session["HTUserName"] != null) && (!string.IsNullOrEmpty(this.Session["HTUserName"].ToString())))
                    {
                        TSL.Model.SYS_users oper = new TSL.BLL.SYS_users().GetModelByName(this.Session["HTUserName"].ToString());
                        if (oper != null)
                            _asuser = oper;
                    }
                }
                return _asuser;
            }
        }
        /// <summary>
        /// 计算返奖模式
        /// </summary>
        public int FJMode(int fdnum)
        {
            if (WebConfig != null)
            {
                return (WebConfig.FatFJ + (fdnum * int.Parse(WebConfig.kedumax.ToString())));
            }
            return 0;
        }
    }
}
